﻿using System.Diagnostics;
using LFSRecord2.Misc;

namespace LFSRecord2.Model.UserActions
{
    public class UserActionKeyFrameOptionChanged : UserActionBase
    {
        // Action description, so we can replay this action (and reverse it)
        public int LayerIndex { get; set; }
        public int PropertyIndex { get; set; }
        public int KeyFrameIndex { get; set; }
        public CustomKeyFrameOptions OldOptions { get; set; }
        public CustomKeyFrameOptions NewOptions { get; set; }

        public UserActionKeyFrameOptionChanged()
        {
            Action = UserActionTypes.KeyFrameOptionChanged;
        }

        public override void DoUndo()
        {
            Debug.WriteLine("Undoing a KeyFrameOptionChanged action");
            if (KeyFrameIndex > LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames.Count - 1)
            {
                Logger.LogError("Invalid keyframe reference while undoing kfOptionAction");
            }
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].Options = OldOptions;
               
        }

        public override void DoRedo()
        {
            Debug.WriteLine("Redoing a KeyFrameOptionChanged action");
            if (KeyFrameIndex > LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames.Count - 1)
            {
                Logger.LogError("Invalid keyframe reference while redoing kfOptionAction");
            }
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].Options = NewOptions;
             
        }
    }
}
